#include "SparseMatrix.cc"

int main(int argc, char **argv)
{
    SparseMatrix<int> **sm;
    SparseMatrix<int> *t;
    SparseMatrix<int> *sum;
    if (argc < 2) {
        cerr << "INVALID PARAMS" << endl
             << "usage = ./out file1 file2 ..." << endl;
        return EXIT_FAILURE;
    }
    int c = argc - 1;
    sm = new (std :: nothrow) SparseMatrix<int> *[c];
    if (sm == NULL) {
        cerr << "NO space to run the main method" << endl;
        return EXIT_FAILURE;
    }
    for (int i = 0; i < c; i++) {
        sm[i] = SparseMatrix<int> :: init(argv[i + 1]);
        if (sm[i] == NULL) {
            cerr << "error creating matrix" << endl;
            delete[] sm;
            return EXIT_FAILURE;
        }
    }
    //sm->print();
    t = new SparseMatrix<int>(sm[0]->getCols(),
                            sm[0]->getRows(), sm[0]->getTerms());
    /*if (sm[0]->transpose(t) == FALSE) {
        cerr << "INSANE ERROR" << endl;
        delete[] sm;
        delete t;

        return EXIT_FAILURE;
    }*/
    sm[0]->print();
    cout << endl << "----------------" << endl;
    sm[1]->print();
    cout << endl << "----------------" << endl;
    //sum = (*sm[0]) + (*sm[1]);
    sum = sm[0]->faster_add(*sm[1]);
    sum->print();
    delete sum;
    cout << "calculating product" << endl;
    sum = (*sm[0]) * (*sm[1]);
    sum->print();
    delete t;
    delete sm;
    delete sum;
    return EXIT_SUCCESS;
}
